<template>
  <div>
    <city-header></city-header>
    <city-search :cities="cities"></city-search>
    <city-list
      :cities="cities"
      :hot="hotCities"
      :letter="letter"
    ></city-list>
    <city-alphabet
      :cities="cities"
      @change="handleLetterChange"
    ></city-alphabet>
  </div>
</template>

<script>
 import axios from 'axios'
 import CityHeader from '../components/city/Header.vue'
 import CitySearch from '../components/city/Search.vue'
 import CityList from '../components/city/List.vue'
 import CityAlphabet from '../components/city/Alphabet.vue'
export default {
  name: 'City',
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  data () {
    return {
      cities: {},
      hotCities: [],
      letter: ''
    }
  },
  methods: {
    async getCityInfo () {
      const {data: { data: res } }= await axios.get('/api/city.json')
          this.cities = res.cities
          this.hotCities = res.hotCities   
    },
    handleLetterChange (letter) {
      this.letter = letter
    }
  },
  mounted () {
    this.getCityInfo()
  }
}
</script>

<style lang="stylus" scoped>

</style>
